 package com.rampage.utils;
 
 import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

 /**
  * 获取 泛型时使用
  * @author chenzipeng
  *
  */
  public class GenericsUtils
  {
    public static Class getGenericClass(Class clazz)
    {
      return getGenericClass(clazz, 0);
    }

    public static Class getGenericClass(Class clazz, int index) {
      Type genType = clazz.getGenericSuperclass();

      if ((genType instanceof ParameterizedType)) {
        Type[] params = ((ParameterizedType)genType).getActualTypeArguments();

        if ((params != null) && (params.length >= index - 1)) {
          return (Class)params[index];
        }
      }
      return null;
    }

  }
